import Vue from 'vue'
import axios from 'axios';
import router from '../router'
Vue.prototype.$axios = axios;

axios.defaults.headers.common['Content-Type'] = 'application/json';

let basedomain = '/_';

let base = basedomain+'/ai/v1/assistant/conversation',// 开始问诊
	base2 = basedomain+'/ai/v1/doctor/entity',
	base3 = basedomain+'/user/v1',
	base4 = basedomain+'/ai/v1/doctor/inquiry';

// 超时时间
 axios.defaults.timeout = 50000;
//axios管理请求头
axios.interceptors.request.use(
	config => {
	    // 这里写死一个token，需要在这里取到设置好的token的值 
	    const token = localStorage.getItem('token');
	    if (token) {
//	    		console.log(token,'api')
	        // 这里将token设置到headers中，header的key是Authorization，这个key值根据你的需要进行修改即可
	        config.headers.Authorization = "bearer " +token;
	    }
	    return config
	},
	error => {
	    return Promise.reject(error)
	});
//axios管理返回错误数据
//axios.interceptors.response.use(
//  response => {
//      return response;
//  },
//  err => {
//  		if(err.response.status===502 || err.response.status===401 || err.response.status===400){
//  			router.replace({path: "errorPage"})
//  		}      
//      return Promise.reject(err);
//  }
//);
//开始
export const urlStart = params => { return axios.post(`${base}/start`, params); };//`${base}/start`
//问诊
export const urlTalk = params => { return axios.post(`${base}/talk`, params); };//`${base}/start`
//症状列表
export const urlSymptomList = params => { return axios.get(`${base2}/symptoms?start=${params.start}&count=${params.count}&options.UserPatient=UserPatient&
	options.gender=${params.gender}&options.age.year=${params.age}&sort=${params.sort}`, params); };
//症状搜索
export const urlSymptomSuggest = params => { return axios.get(`${base2}/suggestion/symptoms?count=10&text=${params.text}&userType=
	UserPatient&gender=${params.gender}&age.year=${params.age}`, params); };
//wiki
export const urlWiki = params => { return axios.get(`${base2}/wiki?type=disease&id=${params.id}`, params); };
//问诊记录
export const urlRecordList = params => { return axios.get(`${base3}/inquiry-records?size=${params.size}&start=${params.start}`, params); };
//是从问诊记录点击进入结果详情
export const urlInquiryRecord = params => { return axios.get(`${base3}/inquiry-record/${params.id}`, params); };
//是从主页面点击进入结果详情
export const urlSavePreview = params => { return axios.post(`${base4}/save-preview`, params); };
//从记录页面点击进入结果详情可以删除记录
export const urlDeleteRecord = params => { return axios.delete(`${base3}/inquiry-record/${params.id}`, params); };

